<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="../page.css">
    <script src="page.js"></script>
    <script src="jquery-1.10.1.min.js"></script>
    <script src="goodlist.js"></script>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        img {
            vertical-align: top;
        }

        li {
            list-style: none;
        }

        a {
            text-decoration: none;
        }

        .searchBox {
            overflow: hidden;
            width: 1280px;
            margin: 0 auto;
        }

        .searchBox .left {
            float: left;
        }

        .searchBox .right {
            float: right;
        }

        .searchBox .right>* {
            float: left;
            margin-left: 30px;
        }

        .wrap {
            width: 1200px;
            margin: 50px auto;
        }

        .wrap ul {
            display: flex;
            flex-wrap: wrap;
            /* justify-content: space-evenly; */
            overflow: hidden;
        }

        .wrap ul>li>a {
            width: 280px;
            float: left;
            border: 1px solid #000;
            box-sizing: border-box;
            margin: 10px;
            padding: 5px;
        }

        .wrap ul>li>a>img {
            width: 100%;
        }

        .header {
            height: 100px;
            background-color: #6ff;
        }

        .pageBox1 {
            width: 1280px;
            margin: 50px auto;
            min-height: 40px;
            background-color: gray;
        }

        .footer {
            height: 100px;
            background-color: #000;
        }
    </style>
</head>

<body>
    <div class="header"></div>
    <div class="searchBox">
        <div class="left">
            <input class="searchCon" type="text">
            <button class="searchBtn">查询</button>
        </div>
        <div class="right">
            <select name="" id="selectNum">
                    <option value="4" selected>每页显示4条</option>
                    <option value="8">每页显示8条</option>
                    <option value="12">每页显示12条</option>
                </select>
            <p>
                排序类型: 编号：
                <input type="radio" name="orderType" checked value="id" id="">| 名称：
                <input type="radio" name="orderType" value="goods_title" id="">| 价格：
                <input type="radio" name="orderType" value="goods_current_price" id="">|
            </p>
            <p>
                排序方式: 升序：
                <input type="radio" name="order" checked value="asc" id=""> 降序：
                <input type="radio" name="order" value="desc" id="">
            </p>
        </div>
    </div>
    <div class="wrap">
        <ul class="box">
            <!-- <li>
                    <img src="http://gw.alicdn.com/bao/uploaded/i2/72458074/TB2oYdsedXnpuFjSZFoXXXLcpXa_!!72458074.jpg"
                        alt="">
                    <div>
                        <p>【移不动】Capcom CFB 怪物猎人 泡狐龙 手办 散货</p>
                        <p><span>600.00</span> <i>100</i></p>
                    </div>
    
                </li> -->
        </ul>

    </div>
    <div class="pageBox1">
        <div class="page">

        </div>
    </div>
    <div class="footer"></div>
</body>
<script>
    var con = $(".searchCon")[0].value
    var orderType = $("input[name='orderType']:first")[0].value
    var order = $("input[name='order']:first")[0].value
    var showPage = 5
    var showNum=4

    // console.log(con, orderType, order)
    $(".searchBtn").click(function() {
        con = $(".searchCon").val()
        update(con,orderType,order,showNum,showPage)
    })
    $("input[name='orderType']").click(function() {
        orderType = this.value
        update(con,orderType,order,showNum,showPage)
    })
    $("input[name='order']").click(function() {
        order = this.value
        update(con,orderType,order,showNum,showPage)
    })
    $("#selectNum").change(function() {
        showNum = this.value*1
        update(con,orderType,order,showNum,showPage)
    })
    update(con,orderType,order,showNum,showPage)
   function update(con,orderType,order,showNum,showPage){
    goodlist.getCount(con, orderType, order).then(function(count) {
        new Page(".page", {
            count: count,
            showNum: showNum,
            showPage: showPage,
            callback: function(pageindex) {
                console.log(con, orderType, order,showNum, pageindex)
                goodlist.getData(con, orderType, order,showNum, pageindex).then(function(data){
                    console.log(data)
                     var html=""
                     data.forEach(item => {
                        html += ` <li productId="${item.goods_id}">
                                        <a href="goodsDetail.html?goodsId=${item.goods_id}">
                                                <img src="http:${item.goods_pic}"
                                                alt="">
                                                <div>
                                                    <p>${item.goods_title}</p>
                                                    <p><span>${item.goods_id}</span> <i>${item.goods_trade_num}</i></p>
                                                </div>
                                            </a>
                                        </li> `
                     }); 
                     $(".box").html(html)
                })
            }
        })
    })
}
</script>

</html>